﻿//拖拽模块
;(function($){
	    $.fn.jndrag = function(settings){
	        
	        
	        var obj = this;
	        var isIE = (document.all) ? true : false;
	    
	        var params = $.extend({
	            handle:$(this)
	        },settings || {});
	    
		    var _x,_y;
		    
		    var handle;
		    if (params.handle != "#this"){ handle =  $(obj.find(params.handle)); }
		    else{ 
		        handle = $(obj);
		    }
		    
		    obj.mousedown(function(){
		        $("div[name!='calendar']").each(function(){
	                $(this).css("z-Index",0);
	            });
	            
	            obj.css("z-Index",100);
		    });
		    
		    $(handle).css("cursor","move");
		    
		    
		    
	        handle.mousedown(function(event){
	        
	            $("div[name!='calendar']").each(function(){
	                $(this).css("z-Index",0);
	            });
	            
		        _x = event.clientX - obj.offset().left;
		        _y = event.clientY - obj.offset().top;
    			
    			
		        obj.bind("mousemove",move).bind("mouseup",stop).bind("blur",stop);
		        obj.css("z-Index",100);
	        });
	        
		    function move(){
			    var top = event.clientY - _y;
			    var left = event.clientX - _x;
    			
                if (top < 0) { top = 0;}
                if (left < 0) { left = 0;}
    			
			    obj.css({position:'absolute', left:left + 'px', top : top + 'px'});
			    
			    if (isIE){
			        obj.get(0).setCapture();
			    }else{
			       event.preventDefault();
			    }
		    }
    		
		    function stop(){
		        obj.unbind("mousemove").unbind("mouseup");
		        
		        if (isIE){ obj.get(0).releaseCapture();}
		    }
	    }
})(jQuery);